// COnLine.cpp: implementation of the COnLine class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "COnLine.h"
#include "../CommSocket/ConstantValue.h"
#include "../CommSocket/CommSocket.h"
/** Process Layer */
#include "../MainFrm.h"
#include "../DSTapeRemoveDoc.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

COnLine::COnLine(CCommSocket* pCommSocket)
{
	m_lnkCommSocket = pCommSocket;
}

COnLine::~COnLine()
{
	
}

int COnLine::SetAGV(CString strEQPID, BOOL bMode)
{
	int nResponse;

	CString strMessage(_T(""));
	CString strMode(_T(""));
	
	if(bMode)	//strMode = "ON";
	{
		strMessage.Format(_T("%s=%s %s=%s\n"), HEADER, CMD_AGV_ON, EQPID, strEQPID);
	}
	else		//strMode = "OFF";
	{
		strMessage.Format(_T("%s=%s %s=%s\n"), HEADER, CMD_AGV_OFF, EQPID, strEQPID);
	}

	nResponse = m_lnkCommSocket->SendData("203_R:0");
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	
	return nResponse;
}

int COnLine::PortUnloading(CString strEQPID)
{
	int nResponse;
	CString strMessage(_T(""));
	
	strMessage.Format(_T("%s=%s %s=%s\n"), HEADER, CMD_PORT_UNLOADING, EQPID, strEQPID);
	
	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	return nResponse;
}

int COnLine::PortLoading(CString strEQPID)
{
	int nResponse;
	CString strMessage(_T(""));

	strMessage.Format(_T("%s=%s %s=%s\n"), HEADER, CMD_PORT_LOADING, EQPID, strEQPID);

	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		return nResponse = ERROR_RESPONSE;
	}

	return nResponse;
}

int COnLine::BCRRead(CString strEQPID, const CString& strLOTID)
{
	int nResponse;
	CString strMessage(_T(""));
	
	strMessage.Format(_T("%s=%s %s=%s %s=%s\n"), HEADER, CMD_BCR_READ, EQPID, strEQPID, LOTID, strLOTID);

	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	return nResponse;
}

int COnLine::ReadyToWork(CString strEQPID, const CString& strLOTID)
{
	int nResponse;
	CString strMessage(_T(""));

	strMessage.Format(_T("%s=%s %s=%s %s=%s\n"), HEADER, CMD_READY_TO_WORK, EQPID, strEQPID, LOTID, strLOTID);

	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	return nResponse;
}

int COnLine::WaferWorkStart(CString strEQPID, const CString& strWaferID, const CString& strSeq, const CString& strLOTID)
{
	int nResponse;
	CString strMessage(_T(""));

	strMessage.Format(_T("%s=%s %s=%s %s=%s %s=%s %s=%s\n"), //CMD=WAFER_START EQPID=4LM01 SEQ=01 SLOT=01 LOTID=GNI284
		HEADER, CMD_WAFER_WORK_START, EQPID, strEQPID, SEQ, strWaferID, SLOT, strSeq, LOTID, strLOTID);

	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	return nResponse;
}

int COnLine::WaferWorkComplete(CString strEQPID, const CString& strWaferID, const CString& strSeq, const CString& strLOTID)
{
	int nResponse;
	CString strMessage(_T(""));
	
	strMessage.Format(_T("%s=%s %s=%s %s=%s %s=%s %s=%s\n"), 
			HEADER, CMD_WAFER_END, EQPID, strEQPID, SEQ, strWaferID, SLOT, strSeq,LOTID,strLOTID);


	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	return nResponse;
}

int COnLine::WorkComplete(CString strEQPID, const CString& strLOTID)
{
	int nResponse;
	CString strMessage(_T(""));

	strMessage.Format(_T("%s=%s %s=%s %s=%s\n"), HEADER, CMD_WORK_END, EQPID, strEQPID, LOTID, strLOTID);
	
	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}
	return nResponse;
}

int COnLine::Alarm(CString strEQPID, const CString& strAlarmID, const CString& strAlarmDescription, BOOL bMode)
{
	int nResponse;
	CString strMessage(_T(""));
	CString strMode(_T(""));

	if(bMode)			strMode = MODE_ON;
	else				strMode = MODE_OFF;

	strMessage.Format(_T("%s=%s %s=%s %s=%s %s=%s %s=%s\n"), 
		HEADER, CMD_ALARM, EQPID, strEQPID, ALARMID, strAlarmID, ALARM, strAlarmDescription, MODE, strMode);
	
	nResponse = m_lnkCommSocket->SendData(strMessage);
	SetSendData(strMessage);
	if (nResponse == SOCKET_ERROR)
	{
		nResponse = ERROR_RESPONSE;
	}

	return nResponse;
}
